#pragma once
#include <iostream>
#include <string>

std::string oper = "+-*/%";

enum
{
    Diverror = 1,
    Moderror,
    Unknow
};

class Task
{
public:
    Task(int data1, int data2, char oper)
        : data1_(data1), data2_(data2), oper_(oper), result_(0), exitcode_(0)
    {}

    void Run()
    {
        switch (oper_)
        {
        case '+':
            result_ = data1_ + data2_;
            break;
        case '-':
            result_ = data1_ - data2_;
            break;
        case '*':
            result_ = data1_ * data2_;
            break;
        case '/':
            if (data2_ == 0)
                exitcode_ = Diverror;
            else
                result_ = data1_ / data2_;
            break;
        case '%':
            if (data2_ == 0)
                exitcode_ = Moderror;
            else
                result_ = data1_ % data2_;
            break;
        default:
            exitcode_ = Unknow;
            break;
        }
    }

    void operator()()
    {
        Run();
    }

    std::string GetTask()
    {
        std::string ret;
        ret += std::to_string(data1_);
        ret += oper_;
        ret += std::to_string(data2_);
        ret += "=?";
        return ret;
    }

    std::string GetResult()
    {
        std::string ret;
        ret += std::to_string(data1_);
        ret += oper_;
        ret += std::to_string(data2_);
        ret += "=";
        ret += std::to_string(result_);
        ret += ", exitcode = ";
        ret += std::to_string(exitcode_);
        return ret;
    }

private:
    int data1_;
    int data2_;
    char oper_;      //直接用char类型，使用者传参为char类型
    int result_;
    int exitcode_;
};